package com.wsx.first.c;


import java.util.*;

/**
 * @author: wangshunxi
 * @date: 2022/5/10 16:22
 * @Description:
 */
public class Main0008 {
    public static class Entry{
        public String key;
        public Integer value;
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int line = Integer.valueOf(scanner.nextLine());
            List<Entry> entries = new ArrayList<>();
            while(scanner.hasNext()){
                Entry entry = new Entry();
                String s = scanner.nextLine();
                String[] split = s.split(" ");
                entry.key = split[0];
                entry.value = Integer.valueOf(split[1]);
                entries.add(entry);
            }
            solution(entries);
        }
    }

    private static void solution(List<Entry> content) {
        Map<String, Integer> map = new HashMap<>();
        content.stream().forEach(e -> {
            Integer val = null;
            if (map.containsKey(e.key)) {
                val = map.get(e.key) + e.value;
            } else {
                val = e.value;
            }
            map.put(e.key, val);
        });
        map.forEach((k,v) -> {
            System.out.println(k + " " + v);
        });
    }


}
